package com.wedo.mall.widget;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.wedo.mall.R;
import com.wedo.mall.entity.Banner;
import com.wedo.mall.util.WUrl;

/**
 * 自定义BannerHolder
 * Created by lxy on 2017/6/29.
 */

public class BannerHolder implements Holder<Banner> {
    private ImageView imageView;

    @Override
    public View createView(Context context) {
        imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//        imageView.setScaleType(ImageView.ScaleType.CENTER);
        return imageView;
    }

    @Override
    public void UpdateUI(Context context, int position, Banner data) {
        String img = WUrl.url(data.image);
        Glide.with(context).load(img).error(R.drawable.place_holder_banner).placeholder(R.drawable.place_holder_banner).diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView);
    }

    public static void align(ConvenientBanner cbBanner) {
        cbBanner.setPageIndicator(new int[]{R.drawable.sign_page_grey, R.drawable.sign_page_blue});
        cbBanner.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT);
    }
}
